In [ ]:
import astropy.io.fits as fits
import numpy as np
import glob
In [ ]:
%pylab
%matplotlib inline
In [ ]:
##read in a sample 0.9m image and print it's dimensions
image1 = fits.getdata("data/wiyn0_9/2016june18/NGC6240/c7558t0054o00.fits")
image1.shape
In [ ]:
##Tell the program how many flat images to combine
nims = ##insert the number of images here before the ##
first_frame = # specify the first frame of the set you want to combine.
##insert the path to the file and basic string that starts out the name of all of the files,
#in quotations.
basestring =
## For example, "/mnt/camp-storage/ATC2016/wiyn_09/Converted2016june20/c7560t"
In [ ]:
##this piece takes your input above and makes a
#3D "cube" of bias-subtracted images for you to work with
dim = len(image1[0])
image_bsub = np.zeros((dim,dim,nims))
for i,file_index in enumerate(range(first_frame,first_frame+nims)):
filename = basestring+'%04i' % file_index +'o00.fits'
print(filename)
image = fits.getdata(filename)
## subtract the bias from the bias overscan regions
overscan=image[4100:4140,4100:4140]
overscan_mean = mean(overscan)
image_bsub[:,:,i] = image - overscan_mean
In [ ]:
##now we'll take the median combination of these images
median_image = median(image_bsub, axis=2)
In [ ]:
In [ ]:
## plot this median image, you may need to add some keywords to imshow to see anything
figure(figsize=(10,10))
imshow(median_image, cmap='magma')
colorbar()
In [ ]:
## write out your new image as a .fits file
fname = "test.fits" ##fill in your desired filename here, in quotes, for example "Rflat.fits"
fits.writeto(fname, median_image)
#if you need to overwrite an existing file, add: clobber=True
In [ ]: